package com.rt.java.util.concurrent;

import java.util.concurrent.atomic.AtomicStampedReference;
import java.util.concurrent.locks.ReentrantLock;

// ABA问题
public class AtomicStampedReferenceDemo {
    public static void main(String[] args) {
        new ReentrantLock().unlock();
        AtomicStampedReference<String> asr = new AtomicStampedReference("张三", 0);
        int[] stampHolder = new int[1];
        String expectedReference = null;
        String newReference = "李四";
        int expectedStamp;
        int newStamp;
        do {
            expectedReference = asr.get(stampHolder);
            expectedStamp = stampHolder[0];
            newStamp = expectedStamp + 1;
        } while (!asr.compareAndSet(expectedReference, newReference, expectedStamp, newStamp));
    }
}


